<template>
	<view class="page-fade-in" :style="{opacity: pageOpc}">
		<template v-if="pageOpc">
			<view class="content" :style="'height:'+windowHeight+'px'">
				<image src="../../static/home/xalinkBg.png" class="Bg"></image>
				<image src="../../static/coupon/shareTips.png" class="shareTips"></image>
				<view class="page-cont flexWarpCenterColumn">
					<view class="coupon-box flexWarpCenterColumn">
						<view class="active-title">{{shareInfo.title}}</view>
						<view class="coupon-item flexWrap">
							<view>{{couponInfo.title}}</view>
							<view>x{{shareInfo.coupon_num}}</view>
						</view>
						<view class="btn" @tap="shareReceive()" v-if="isLink==0">开心收下</view>
						<view class="btn" v-else>已领取</view>
					</view>
					<view class="store-info">
						<view class="info-item flexWrapNo">
							<text style="flex: none;">适用门店：</text>
							<text>{{shop_name}}</text>
						</view>
						<view class="info-item flexWrapNo">
							<view style="flex: none;">门店地址：</view>
							<view>{{location}}</view>
						</view>
					</view>
					<view class="join-btn" @tap="joinStore()">进入门店-在线预约</view>
				</view>
			</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageOpc:0,
				windowHeight:"",
				coupon_share_id:"",
				shop_name:"",
				location:"",
				store_id:"",
				couponInfo:{
					title:"加载中...",
				},
				isLink:0,
				shareInfo:{
					title:"加载中...",
					coupon_num:0
				}
			}
		},
		created() {
			const {
				windowWidth,
				windowHeight
			} = uni.getSystemInfoSync()
		
			this.windowHeight = windowHeight;
		},
		onLoad(ops) {
			this.coupon_share_id=ops.coupon_share_id
			this.getShareInfo();
		},
		onShow() {
			if(uni.getStorageSync('token')){
				this.getShareInfo();
			}
		},
		onReady(){
			setTimeout(() => {
				this.pageOpc=1
			}, 100)
		},
		onShareAppMessage: function(e) {
			let that=this
			return {
				title:that.couponInfo.title,
				path: `/pages/home/linkCoupon?coupon_share_id=${that.coupon_share_id}`,
				imageUrl:"/static/home/xalinkBg.png",
				success: (res) => {
					uni.showToast({
						title: '分享成功',
						icon: 'success',
						duration: 1500
					})
				}
			}
		},
		methods: {
			// 
			getShareInfo(){
				this.$request.post(this.$api.shareInfo, {
					coupon_share_id:this.coupon_share_id,
					token:uni.getStorageSync('token')
				}, {}).then(res => {
					let {
						data={}
					}=res;
					this.couponInfo=data.coupon_info
					this.shop_name=data.store_info.shop_name
					this.location=data.store_info.location
					this.store_id=data.store_info.id
					this.shareInfo=data.share_info
					this.isLink=data.share_info.status
					uni.setStorageSync('store_id',this.store_id)
				})
			},
			shareReceive(){
				this.$request.post(this.$api.shareReceive, {
					coupon_share_id:this.coupon_share_id
				}, {
					token:true
				}).then(res => {
					if (res.code==1) {
						this.isLink=1
						this.$tools.showToast('领取成功');
					}
				})
			},
			joinStore(){
				uni.switchTab({
					url:'/pages/home/index?store_id='+this.store_id
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #F54422;
	}
	.Bg{
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		height: 360upx;
		margin: auto;
	}
	.shareTips{
		width: 376upx;
		height: 74upx;
		position: fixed;
		top: 0;
		right: 44upx;
	}
	.page-cont{
		position: fixed;
		left: 0;
		right: 0;
		top: 240upx;
		margin: auto;
		.coupon-box{
			width: 646upx;
			height: 768upx;
			justify-content: center;
			background: url('https://static.mo-yu.vip/wechat/images/coupnBg.png')no-repeat center/100% 100%;
			.active-title{
				font-size: 48rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #760D00;
				margin-bottom: 50upx;
				margin-top: 120upx;
			}
			.coupon-item{
				font-size: 32rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #DD1800;
				width: 352rpx;
				height: 110rpx;
				padding: 0 32upx;
				line-height: 110upx;
				background: #FFFAD3;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
			}
			.btn{
				font-size: 36rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #9F610F;
				margin-top: 160upx;
				width: 438upx;
				height: 100upx;
				line-height: 100upx;
				background-color: #FFDCAA;
				border-radius: 50upx;
				text-align: center;
			}
		}
		.store-info{
			width: 646upx;
			.info-item{
				font-size: 28rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				margin-bottom: 24upx;
				align-items: baseline;
			}
		}
		.join-btn{
			font-size: 32rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
			width: 370rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			background: #FCAB11;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin-top: 50upx;
		}
	}
</style>
